package com.huike.clues.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huike.clues.domain.SysDictData;
import com.huike.clues.domain.dto.SysDictDto;
import com.huike.clues.domain.vo.SysDictDataVo;
import com.huike.clues.mapper.DictDataMapper;
import com.huike.clues.service.DictService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DictServiceImpl extends ServiceImpl<DictDataMapper, SysDictData> implements DictService {
    /**
     * 新增字典类型
     *
     * @param data
     */
    @Autowired
    private DictDataMapper dictDataMapper;
    @Override
    public void addDictType(SysDictData data) {
        int count = this.count(Wrappers.<SysDictData>lambdaQuery()
                .eq(SysDictData::getDictCode, data.getDictCode()));
        if (count > 0){
            throw new RuntimeException("字典名称已存在");
        }
        this.save(data);
    }

    /**
     * 分页查询数据字典类型信息
     *
     * @param dto
     */
    @Override
    public List<SysDictDataVo> selectAll(SysDictDto dto) {
        return dictDataMapper.selectAlertDataList(dto);
    }


}
